//
//  MessageObjSetViewController.swift
//  MyTest
//
//  Created by guanzhongwang on 2021/5/10.
//

import UIKit

class MessageObjSetViewController: CommonViewController {
    private var cells:Array<ReceiveRangeView> = []
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        let tips = UILabel()
        tips.text = "接收范围"
        tips.textColor = B999_TITLE_COLOR
        view.addSubview(tips)
        tips.font = Font_Size_12
        tips.snp.makeConstraints({
            if #available(iOS 11.0, *) {
                $0.top.equalTo(view.safeAreaLayoutGuide.snp.top).offset(20)
            } else {
                // Fallback on earlier versions
                $0.top.equalTo(20)
            }
            $0.left.equalTo(15)
        })
        let titles = ["所有人","我关注的人","不接收此类消息"]
        for i in 0..<titles.count {
            let cell = ReceiveRangeView()
            cell.changeState(selected: i == 0)
            cell.setTitle(titles[i],id: 100+i)
            view.addSubview(cell)
            cell.delegate = self
            cell.snp.makeConstraints({
                $0.height.equalTo(44)
                $0.left.right.equalTo(0)
                $0.top.equalTo(tips.snp.bottom).offset(44*i+10)
            })
            cells.append(cell)
        }
    }
 

}
extension MessageObjSetViewController:ReceiveRangeViewDelegate{
    func viewSelected(id: Int) {
        for cell in cells {
            cell.changeState(selected: cell.id == id)
        }
    }
}
